<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;
use think\Db;

/**
 * 文章类合并控制器
 */
class Merge extends AdminBase
{
    public $articleType = [
        1  => "首页展示",
        2  => "关于我们-公司简介",
        3  => "公司业务-掘金产品",
        4  => "公司业务-高端网站建设",
        5  => "公司业务-微信营销",
        6  => "公司业务-平台网站开发",
        7  => "新闻资讯-掘金课堂",
        8  => "新闻资讯-行业新闻",
        9  => "加入我们-人才招聘",
        10 => "新闻资讯-掘金课堂",
        11 => "新闻资讯-行业新闻",
        12 => "加入我们-人才招聘",
    ];
    
    
    /**
     * 首页 - 模块1
     */
    public function homeFirst()
    {
        $this->commonEdit(10, 'homeFirst');
        
        return $this->fetch('homepage_edit');
    }
    
    
     /**
     * 首页 - 模块2
     */
    public function homeSecond()
    {
        $this->commonEdit(11, 'homeSecond');
        
        return $this->fetch('homepage_edit');
    }
    
    
     /**
     * 首页 - 模块3
     */
    public function homeThird()
    {
        $this->commonEdit(12, 'homeThird');

        return $this->fetch('homepage_edit');
    }


    
    /**
     * 首页 模块文章添加
     */
    public function homePageAdd()
    {
        
    }
     
    
    /**
     * 关于我们-公司简介
     */
    public function introduction()
    {
        
        $this->commonEdit(2,'introduction');
       
        return $this->fetch('about_edit');
    } 
    
    
    /**
     * 掘金产品
     */
    public function myProduct()
    {
        $this->commonEdit(3,'myProduct');
       
        return $this->fetch('bussiness_edit');
    }
    
    
    /**
     * 高端网站建设
     */
    public function websiteBuild()
    {
        $this->commonEdit(4,'websiteBuild');
       
        return $this->fetch('bussiness_edit');
    }
    
    /**
     * 微信营销
     */
    public function wxMarket()
    {
        $this->commonEdit(5,'wxMarket');
       
        return $this->fetch('bussiness_edit');
    }
    
    
    /**
     * 平台网站开发
     */
    public function platform()
    {
        $this->commonEdit(6,'platform');
       
        return $this->fetch('bussiness_edit');
    } 
 
     
    
    /**
     * 新闻资讯-掘金课堂-列表
     */
      public function newsList()
    {
        
        $this->commonList(7);
       
        return $this->fetch('news_list');
    }
    
    
    /**
     * 新闻资讯-掘金课堂-添加
     */
    public function newsAdd()
    {
        $this->articleCommon(7,'newsList');
        
        $this->assign('info',[]);
        
        return $this->fetch('news_edit');
    }
    
    
    /**
     * 新闻资讯-掘金课堂-编辑
     */
    public function newsEdit()
    {
        $this->commonEdit(7,'newsList');
        
        return $this->fetch('news_edit');
    }
    

    /**
     * 新闻资讯-行业新闻-列表
     */
      public function industryList()
    {
        
        $this->commonList(8);
       
        return $this->fetch('industry_list');
    }
    
    
    /**
     * 新闻资讯-行业新闻-添加
     */
    public function industryAdd()
    {
        $this->articleCommon(8,'industryList');
        
        $this->assign('info',[]);
        
        return $this->fetch('industry_edit');
    }
    
    
    /**
     * 新闻资讯-行业新闻-编辑
     */
    public function industryEdit()
    {
        
        $this->commonEdit(8,'newsList');
        
        return $this->fetch('industry_edit');
    }

    
    /**
     * 加入我们-人才应聘-编辑
     */
    public function toEmploy()
    {
        
        $this->commonList(9);
        
        return $this->fetch('employ_list');
    }
    
    
    /**
     * 加入我们-人才应聘-编辑
     */
    public function employEdit()
    {
        
        $this->commonEdit(9,'toemploy');
        
        return $this->fetch('join_edit');
    }
    
    
     /**
     * 加入我们-人才应聘-添加
     */
    public function employAdd()
    {
        
        $this->articleCommon(9,'toemploy');
        
        $this->assign('info',[]);
        
        return $this->fetch('join_edit');
    }
    
    
        
    /**
     * 通用文章列表获取方法
     * @param type $type 文章类型
     * @return type
     */
     public function commonList($type)
    {
         
        $where['a.category_id'] = $type;
        
        $this->assign('list', $this->logicArticle->getArticleList($where, 'a.*,m.nickname,c.name as category_name', 'sort,a.updated_at desc'));
    }
  
    
    
    /**
     * 通用获取文章编辑信息
     * @param type $type 文章类型
     * @return type
     */
    public function commonEdit($type,$url)
    {
       
        $this->articleCommon($type,$url);

        if(empty($this->param['id'])){
            
            $article_id = $this->getIdByCategoryId($type);
            
        }else{
            
            $article_id = $this->param['id'];
        }

        $info = $this->logicArticle->getArticleInfo(['a.id' => $article_id], 'a.*,m.nickname,c.name as category_name');

        !empty($info) && $info['img_ids_array'] = str2arr($info['img_ids']);
        
        $this->assign('info', $info);
    }
    
    
    /**
     * 文章添加与编辑通用方法
     */
    public function articleCommon($type,$url)
    {
        
        IS_POST && $this->jump($this->logicArticle->articleEdit($this->param,$type,$url));
    }
    
    
    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('Article', $this->param));
    }
    
    
    /**
     * 通过分类获取文章ID
     */
    public function getIdByCategoryId($type)
    {
        
        $article = Db::query('select id from jj_article where category_id=?',[$type]);
        
        $articleId = $article?$article[0]['id']:0;
        
        return $articleId;
    }
    
    
     /**
     * 排序
     */
    public function setSort()
    {
        
        $this->jump($this->logicAdminBase->setSort('Article', $this->param));
    }
}
